/*
 * @Author: Await
 * @Date: 2025-04-17 15:15:44
 * @LastEditors: Await
 * @LastEditTime: 2025-05-06 17:45:35
 * @Description: 请填写简介
 */
import { TextStyle, Position } from './index'; // 确保导入基础类型

/**
 * 图表类型枚举
 */
export enum ChartType {
    // 2D图表
    LINE = 'line',
    BAR = 'bar',
    PIE = 'pie',
    SCATTER = 'scatter',
    GRAPH = 'graph',
    TREE = 'tree',
    GAUGE = 'gauge',
    RADAR = 'radar',
    HEATMAP = 'heatmap',

    // 3D图表
    BAR_3D = 'bar3D',
    SCATTER_3D = 'scatter3D',
    PATH_3D = 'lines3D', // 对应原生ECharts-GL的lines3D类型
    LINE_3D = 'line3D',
    SURFACE_3D = 'surface3D'
}

// 确保类型也能被导出为类型别名，增加兼容性
export type ChartTypeValue = keyof typeof ChartType;

/**
 * 标题配置
 */
export interface TitleConfig {
    show?: boolean;
    text?: string;
    subtext?: string;
    position?: { left?: string | number; top?: string | number; right?: string | number; bottom?: string | number };
    textStyle?: TextStyle;
    subtextStyle?: TextStyle;
    textAlign?: 'auto' | 'left' | 'right' | 'center';
    textBaseline?: 'auto' | 'top' | 'middle' | 'bottom';
    padding?: number | number[];
    itemGap?: number;
    zlevel?: number;
    z?: number;
    backgroundColor?: string;
    borderColor?: string;
    borderWidth?: number;
    borderRadius?: number | number[];
    shadowBlur?: number;
    shadowColor?: string;
    shadowOffsetX?: number;
    shadowOffsetY?: number;
    link?: string;
    target?: 'self' | 'blank';
    triggerEvent?: boolean;
}

/**
 * 图例配置
 */
export interface LegendConfig {
    show?: boolean;
    orient?: 'horizontal' | 'vertical';
    position?: { left?: string | number; top?: string | number; right?: string | number; bottom?: string | number };
    textStyle?: TextStyle;
}

/**
 * 坐标轴标签配置
 */
export interface AxisLabelConfig {
    show?: boolean;
    rotate?: number;
    color?: string;
    fontSize?: number;
    formatter?: string | ((value: any) => string) | Function;
    interval?: number | string | Function;
    inside?: boolean;
    margin?: number;
    fontStyle?: string;
    fontWeight?: string | number;
    fontFamily?: string;
    align?: 'left' | 'center' | 'right' | string;
    verticalAlign?: string;
    padding?: number;
    [key: string]: any; // 允许使用字符串索引访问
}

/**
 * 坐标轴线样式配置
 */
export interface AxisLineStyleConfig {
    color?: string;
    width?: number;
    type?: 'solid' | 'dashed' | 'dotted';
}

/**
 * 坐标轴线配置
 */
export interface AxisLineConfig {
    show?: boolean;
    onZero?: boolean;
    lineStyle?: AxisLineStyleConfig;
}

/**
 * 坐标轴刻度配置
 */
export interface AxisTickConfig {
    show?: boolean;
    alignWithLabel?: boolean;
    interval?: number | string | Function;
    inside?: boolean;
    length?: number;
    lineStyle?: AxisLineStyleConfig;
}

/**
 * 坐标轴分隔线配置
 */
export interface SplitLineConfig {
    show?: boolean;
    interval?: number | string | Function;
    lineStyle?: {
        color?: string | string[];
        width?: number;
        type?: 'solid' | 'dashed' | 'dotted';
    };
    [key: string]: any; // 允许使用字符串索引访问
}

/**
 * 坐标轴名称配置
 */
export interface AxisNameConfig {
    show?: boolean;
    text?: string;
    location?: 'start' | 'middle' | 'end';
    textStyle?: {
        color?: string;
        fontSize?: number;
        fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | string | number;
        [key: string]: any;
    };
    [key: string]: any; // 允许使用字符串索引访问
}

/**
 * 坐标轴通用配置
 */
export interface AxisGeneralConfig {
    show?: boolean;
    type?: 'value' | 'category' | 'time' | 'log';
    position?: 'top' | 'bottom' | 'left' | 'right';
    nameGap?: number;
    nameRotate?: number;
    inverse?: boolean;
    min?: number | string | Function | 'dataMin';
    max?: number | string | Function | 'dataMax';
    scale?: boolean;
    splitNumber?: number;
    minInterval?: number;
    maxInterval?: number;
    interval?: number;
    boundaryGap?: boolean | [number, number];
    zlevel?: number;
    z?: number;
    silent?: boolean;
    [key: string]: any; // 允许使用字符串索引访问
}

/**
 * 坐标轴配置
 */
export interface AxisConfig {
    x?: AxisGeneralConfig;
    y?: AxisGeneralConfig;
    z?: AxisGeneralConfig;
    xAxisLabel?: AxisLabelConfig;
    yAxisLabel?: AxisLabelConfig;
    zAxisLabel?: AxisLabelConfig;
    xAxisLine?: AxisLineConfig;
    yAxisLine?: AxisLineConfig;
    zAxisLine?: AxisLineConfig;
    xAxisTick?: AxisTickConfig;
    yAxisTick?: AxisTickConfig;
    zAxisTick?: AxisTickConfig;
    xSplitLine?: SplitLineConfig;
    ySplitLine?: SplitLineConfig;
    zSplitLine?: SplitLineConfig;
    xAxisName?: AxisNameConfig;
    yAxisName?: AxisNameConfig;
    zAxisName?: AxisNameConfig;
    xAxisGeneral?: AxisGeneralConfig;
    yAxisGeneral?: AxisGeneralConfig;
    zAxisGeneral?: AxisGeneralConfig;
}

/**
 * 视图控制配置 (3D)
 */
export interface ViewControlConfig {
    // 自动旋转
    autoRotate?: boolean;
    autoRotateSpeed?: number;

    // 视角角度
    alpha?: number; // 垂直旋转角度
    beta?: number;  // 水平旋转角度

    // 视角中心点
    center?: [number, number, number];

    // 视角距离
    distance?: number;
    minDistance?: number;
    maxDistance?: number;

    // 视角限制
    minAlpha?: number;
    maxAlpha?: number;
    minBeta?: number;
    maxBeta?: number;

    // 交互灵敏度
    rotateSensitivity?: number;
    zoomSensitivity?: number;
    panSensitivity?: number;

    // 动画
    damping?: number;
    animation?: boolean;
    animationDurationUpdate?: number;

    // 正交投影
    orthographic?: boolean;
    orthographicSize?: number;
}

/**
 * 聚光灯配置
 */
export interface SpotLight {
    intensity?: number;
    color?: string;
    alpha?: number;
    beta?: number;
    distance?: number;
    range?: number;
    focus?: number;
    angle?: number;
}

/**
 * 光照配置 (3D)
 */
export interface LightConfig {
    main?: {
        intensity?: number;
        shadow?: boolean;
        shadowQuality?: 'low' | 'medium' | 'high' | 'ultra';
        alpha?: number;
        beta?: number;
        color?: string;
    };
    ambient?: {
        intensity?: number;
        color?: string;
    };
    ambientCubemap?: {
        texture?: string | null;
        exposure?: number;
        diffuseIntensity?: number;
        specularIntensity?: number;
    };
    spotLights?: SpotLight[];
}

/**
 * 后期处理配置 (3D)
 */
export interface PostProcessConfig {
    // 环境光遮蔽 (SSAO)
    ssao?: {
        enable?: boolean;
        radius?: number;
        quality?: 'low' | 'medium' | 'high' | 'ultra';
        intensity?: number;
    };

    // 景深效果 (DOF)
    depthOfField?: {
        enable?: boolean;
        focalDistance?: number;
        focalRange?: number;
        blurRadius?: number;
        quality?: 'low' | 'medium' | 'high';
    };

    // 体积光/光线散射
    volumetricLight?: {
        enable?: boolean;
        intensity?: number;
        quality?: 'low' | 'medium' | 'high';
    };

    // 屏幕空间反射 (SSR)
    screenSpaceReflection?: {
        enable?: boolean;
        quality?: 'low' | 'medium' | 'high';
        maxRoughness?: number;
    };

    // 颜色校正
    colorCorrection?: {
        enable?: boolean;
        exposure?: number;
        brightness?: number;
        contrast?: number;
        saturation?: number;
        gamma?: number;
    };

    // 泛光效果
    bloom?: {
        enable?: boolean;
        intensity?: number;
        threshold?: number;
        radius?: number;
    };

    // 抗锯齿
    antialiasing?: {
        enable?: boolean;
        method?: 'none' | 'fxaa' | 'smaa' | 'taa';
        quality?: 'low' | 'medium' | 'high';
    };

    // 环境
    ambient?: {
        enable?: boolean;
        color?: string;
        intensity?: number;
    };
}

/**
 * 标签配置
 */
export interface LabelConfig {
    show?: boolean;
    // Restrict position to common string values for Select component compatibility
    position?: 'top' | 'left' | 'right' | 'bottom' | 'inside' | 'outside' | 'insideLeft' | 'insideRight' | 'insideTop' | 'insideBottom' | 'insideTopLeft' | 'insideBottomLeft' | 'insideTopRight' | 'insideBottomRight';
    fontSize?: number;
    color?: string;
    formatter?: string | ((params: any) => string);
    backgroundColor?: string | object; // 添加 backgroundColor
    // ... 其他 ECharts label 支持的属性
}

/**
 * 强调样式配置
 */
export interface EmphasisConfig {
    label?: LabelConfig;
    focus?: 'series' | 'point' | 'none';
    scale?: boolean | number; // 通常在emphasis中使用，但加在这里兼容
    itemStyle?: ItemStyleConfig; // 使用下面定义的 ItemStyleConfig
    // ... 其他 ECharts emphasis 支持的属性
}

/**
 * 图形样式配置
 */
export interface ItemStyleConfig {
    color?: string | object; // 颜色可以是渐变等
    borderColor?: string;
    borderWidth?: number;
    opacity?: number;
    borderRadius?: number | number[] | string | string[]; // 添加 borderRadius
    shadowBlur?: number;        // 添加 shadowBlur
    shadowColor?: string;       // 添加 shadowColor
    shadowOffsetX?: number;     // 添加 shadowOffsetX
    shadowOffsetY?: number;     // 添加 shadowOffsetY
    offset?: number;            // 添加 offset (饼图用)
    scale?: boolean | number;   // 添加 scale (高亮用)
    // ... 其他 ECharts itemStyle 支持的属性
}

/**
 * 线条样式配置
 */
export interface LineStyleConfig {
    color?: string | object;
    width?: number;
    type?: 'solid' | 'dashed' | 'dotted';
    opacity?: number;
    // ... 其他 ECharts lineStyle 支持的属性
}

/**
 * 区域样式配置
 */
export interface AreaStyleConfig {
    show?: boolean;
    color?: string | object;
    opacity?: number;
    // ... 其他 ECharts areaStyle 支持的属性
}

/**
 * 系列配置项
 */
export interface SeriesItem {
    name?: string;
    type?: ChartType; // 系列本身也可以指定类型
    stack?: string;
    connectNulls?: boolean;
    itemStyle?: ItemStyleConfig;
    label?: LabelConfig;         // 添加 label
    emphasis?: EmphasisConfig;   // 添加 emphasis
    // 2D 特有
    areaStyle?: AreaStyleConfig; // 添加 areaStyle
    lineStyle?: LineStyleConfig; // 添加 lineStyle
    symbol?: string;
    symbolSize?: number; // 修改为 number | undefined 以匹配InputNumber
    smooth?: boolean | number;
    barWidth?: number | string;
    radius?: string | number | (string | number)[]; // 添加 radius
    center?: (string | number)[];                 // 添加 center
    // 3D 特有
    shading?: string;            // 添加 shading
    coordinateSystem?: 'globe' | 'cartesian3D';  // 添加坐标系类型
    // 通用
    dataField?: string; // 假设用于数据映射
    data?: any[]; // 系列可以直接包含数据
    [key: string]: any; // 允许其他特定属性
}

/**
 * Grid 配置
 */
export interface GridConfig {
    show?: boolean;
    left?: string | number;
    top?: string | number;
    right?: string | number;
    bottom?: string | number;
    width?: string | number;
    height?: string | number;
    containLabel?: boolean;
    backgroundColor?: string;
    borderColor?: string;
    borderWidth?: number;
    borderRadius?: number;
    zlevel?: number;
    z?: number;
    shadowBlur?: number;
    shadowColor?: string;
    shadowOffsetX?: number;
    shadowOffsetY?: number;
    // 3D Grid 特有
    boxWidth?: number;
    boxDepth?: number;
    boxHeight?: number;
    // ... 其他 grid/grid3D 属性
}

/**
 * Toolbox Feature 配置
 */
export interface ToolboxFeatureConfig {
    saveAsImage?: { show?: boolean; type?: 'png' | 'jpeg'; name?: string; backgroundColor?: string; pixelRatio?: number };
    restore?: { show?: boolean };
    dataView?: { show?: boolean; readOnly?: boolean; optionToContent?: Function; contentToOption?: Function; buttonColor?: string };
    dataZoom?: { show?: boolean; yAxisIndex?: 'none' | number | number[] | boolean; xAxisIndex?: 'none' | number | number[] | boolean };
    magicType?: { show?: boolean; type?: ('line' | 'bar' | 'stack' | 'tiled')[] };
    brush?: any; // 类型较复杂，暂用any
    // ... 其他 feature
}

/**
 * Toolbox 配置
 */
export interface ToolboxConfig {
    show?: boolean;
    orient?: 'horizontal' | 'vertical';
    itemSize?: number;
    itemGap?: number;
    left?: string | number;
    top?: string | number;
    right?: string | number;
    bottom?: string | number;
    feature?: ToolboxFeatureConfig;
    // ... 其他 toolbox 属性
}

/**
 * VisualMap 配置 (简化，可根据需要扩展)
 */
export interface VisualMapConfig {
    show?: boolean;
    type?: 'continuous' | 'piecewise';
    min?: number;
    max?: number;
    inRange?: { color?: string[]; symbolSize?: number[]; opacity?: number[] };
    calculable?: boolean;
    orient?: 'horizontal' | 'vertical';
    left?: string | number;
    top?: string | number;
    right?: string | number;
    bottom?: string | number;
    textStyle?: TextStyle;  // 添加textStyle属性
    // ... 其他 visualMap 属性
}

/**
 * 添加 RadarConfig 定义
 */
export interface RadarIndicatorConf {
    name: string;
    max?: number;
    min?: number;
    color?: string;
}

export interface RadarConfig {
    indicator?: RadarIndicatorConf[];
    shape?: 'polygon' | 'circle';
    radius?: string | number;
    center?: (string | number)[];
    splitNumber?: number;
    axisName?: { show?: boolean; formatter?: string | ((name: string, indicator: RadarIndicatorConf) => string); color?: string; };
    // ... 其他 radar 属性
}

/**
 * 主题配置
 */
export interface ThemeConfig {
    themeName?: string;
    // 全局配置
    color?: string[];
    backgroundColor?: string;
    textStyle?: TextStyle;

    // 组件配置
    title?: {
        textStyle?: TextStyle;
        subtextStyle?: TextStyle;
    };

    line?: {
        symbol?: string;
        symbolSize?: number;
        smooth?: boolean;
        lineStyle?: {
            width?: number;
            type?: 'solid' | 'dashed' | 'dotted';
        };
    };

    bar?: {
        barWidth?: string;
        barGap?: string;
        itemStyle?: {
            barBorderWidth?: number;
            barBorderRadius?: number;
        };
    };

    pie?: {
        borderWidth?: number;
        borderRadius?: number;
        label?: {
            color?: string;
        };
    };

    scatter?: {
        symbol?: string;
        symbolSize?: number;
    };

    radar?: {
        symbolSize?: number;
        lineStyle?: {
            width?: number;
        };
        areaStyle?: {
            opacity?: number;
        };
    };

    map?: {
        itemStyle?: {
            areaColor?: string;
            borderColor?: string;
            borderWidth?: number;
        };
        label?: {
            color?: string;
        };
        emphasis?: {
            itemStyle?: {
                areaColor?: string;
                borderColor?: string;
                borderWidth?: number;
            };
            label?: {
                color?: string;
            };
        };
    };

    graph?: {
        symbolSize?: number;
        itemStyle?: {
            borderWidth?: number;
        };
        lineStyle?: {
            width?: number;
            curveness?: number;
        };
        label?: {
            color?: string;
        };
    };

    candlestick?: {
        itemStyle?: {
            color?: string;
            color0?: string;
            borderColor?: string;
            borderColor0?: string;
            borderWidth?: number;
        };
    };

    axis?: {
        axisLine?: {
            show?: boolean;
            lineStyle?: {
                color?: string;
                width?: number;
                type?: 'solid' | 'dashed' | 'dotted';
            };
        };
        axisTick?: {
            show?: boolean;
            lineStyle?: {
                color?: string;
                width?: number;
            };
            length?: number;
        };
        axisLabel?: {
            show?: boolean;
            color?: string;
            fontSize?: number;
            rotate?: number;
        };
        splitLine?: {
            show?: boolean;
            lineStyle?: {
                color?: string | string[];
                width?: number;
                type?: 'solid' | 'dashed' | 'dotted';
            };
        };
        splitArea?: {
            show?: boolean;
            areaStyle?: {
                color?: string[];
            };
        };
    };

    legend?: {
        textStyle?: {
            color?: string;
            fontSize?: number;
            fontWeight?: string;
            fontFamily?: string;
        };
        itemGap?: number;
        icon?: string;
        pageIcons?: {
            horizontal?: string[];
            vertical?: string[];
        };
        inactiveColor?: string;
        itemSize?: number;
    };

    tooltip?: {
        backgroundColor?: string;
        borderColor?: string;
        borderWidth?: number;
        padding?: number;
        textStyle?: {
            color?: string;
            fontSize?: number;
            fontFamily?: string;
        };
        borderRadius?: number;
    };

    toolbox?: {
        iconStyle?: {
            normal?: {
                borderColor?: string;
                color?: string;
                borderWidth?: number;
                borderType?: string;
            };
            emphasis?: {
                borderColor?: string;
                color?: string;
                borderWidth?: number;
                borderType?: string;
            };
        };
    };

    timeline?: {
        axisType?: string;
        lineStyle?: {
            color?: string;
            width?: number;
            type?: string;
        };
        itemStyle?: {
            color?: string;
            borderWidth?: number;
            borderColor?: string;
            symbolSize?: number;
        };
        controlStyle?: {
            color?: string;
            borderColor?: string;
            borderWidth?: number;
        };
        checkpointStyle?: {
            color?: string;
            borderColor?: string;
            borderWidth?: number;
        };
        label?: {
            color?: string;
            fontSize?: number;
        };
        emphasis?: {
            itemStyle?: {
                color?: string;
                borderWidth?: number;
                borderColor?: string;
                symbolSize?: number;
            };
            controlStyle?: {
                color?: string;
                borderColor?: string;
                borderWidth?: number;
            };
            label?: {
                color?: string;
                fontSize?: number;
            };
        };
    };

    visualMap?: {
        continuous?: {
            inRange?: {
                color?: string[];
                symbolSize?: number[];
                opacity?: number[];
            };
            textStyle?: {
                color?: string;
            };
        };
        piecewise?: {
            inRange?: {
                color?: string[];
            };
            textStyle?: {
                color?: string;
            };
        };
    };
}

/**
 * 数据区域缩放组件配置
 */
export interface DataZoomConfig {
    // 基础属性
    show?: boolean;
    type?: 'slider' | 'inside' | 'select';
    id?: string;
    disabled?: boolean;

    // 指定哪些坐标轴被控制
    xAxisIndex?: number | number[] | 'all';
    yAxisIndex?: number | number[] | 'all';
    radiusAxisIndex?: number | number[] | 'all';
    angleAxisIndex?: number | number[] | 'all';

    // 显示范围
    start?: number; // 百分比，0 - 100
    end?: number; // 百分比，0 - 100
    startValue?: number | string | Date;
    endValue?: number | string | Date;
    minSpan?: number;
    maxSpan?: number;
    minValueSpan?: number | string | Date;
    maxValueSpan?: number | string | Date;

    // 行为
    orient?: 'horizontal' | 'vertical';
    zoomLock?: boolean;
    throttle?: number;
    rangeMode?: ['value' | 'percent', 'value' | 'percent'];

    // 样式相关（主要针对 slider 类型）
    backgroundColor?: string;
    borderColor?: string;
    borderWidth?: number;
    fillerColor?: string;
    handleIcon?: string;
    handleSize?: string | number;
    handleStyle?: {
        color?: string;
        borderColor?: string;
        borderWidth?: number;
        borderType?: string;
        shadowBlur?: number;
        shadowColor?: string;
        shadowOffsetX?: number;
        shadowOffsetY?: number;
        opacity?: number;
    };
    moveHandleIcon?: string;
    moveHandleSize?: number;
    moveHandleStyle?: any; // 与handleStyle结构相同

    // 布局相关
    left?: string | number;
    top?: string | number;
    right?: string | number;
    bottom?: string | number;
    width?: string | number;
    height?: string | number;

    // 标签样式
    labelFormatter?: string | Function;
    labelPrecision?: number | string;

    // inside类型特有
    zoomOnMouseWheel?: boolean | 'shift' | 'ctrl' | 'alt';
    moveOnMouseMove?: boolean | 'shift' | 'ctrl' | 'alt';
    moveOnMouseWheel?: boolean | 'shift' | 'ctrl' | 'alt';
    preventDefaultMouseMove?: boolean;

    // 高级设置
    filterMode?: 'filter' | 'weakFilter' | 'empty' | 'none';
    dataBackground?: {
        lineStyle?: any;
        areaStyle?: any;
    };
    selectedDataBackground?: {
        lineStyle?: any;
        areaStyle?: any;
    };

    // 文字样式设置
    textStyle?: {
        color?: string;
        fontStyle?: string;
        fontWeight?: string | number;
        fontFamily?: string;
        fontSize?: number;
    };

    // 其他
    brushSelect?: boolean;
    brushStyle?: any;
    emphasis?: {
        handleStyle?: any;
        moveHandleStyle?: any;
    };
}

/**
 * 图表配置接口 (最终修正版)
 */
export interface ChartConfig {
    type: ChartType;
    title?: TitleConfig;
    legend?: LegendConfig;
    axis?: AxisConfig;       // 使用导入的 AxisConfig
    series?: SeriesItem[];
    theme?: string | ThemeConfig; // 主题可以是字符串或主题配置对象
    grid?: GridConfig;       // 添加 GridConfig
    tooltip?: any;           // Tooltip 暂时用 any，可细化
    toolbox?: ToolboxConfig; // 添加 ToolboxConfig
    visualMap?: VisualMapConfig; // 使用单个对象类型
    radar?: RadarConfig; // 添加 radar 配置
    // 添加dataZoom配置
    dataZoom?: DataZoomConfig | DataZoomConfig[];
    // 3D 特有配置 (使用导入的)
    viewControl?: ViewControlConfig;
    light?: LightConfig;
    postProcess?: PostProcessConfig;
    // 3D 路径图特有配置
    coordinateSystem?: 'globe' | 'cartesian3D'; // 坐标系类型
    globe?: any; // globe配置，用于地球模式
    // 其他 ECharts 配置项
    color?: string[];
    backgroundColor?: string | object;
    animation?: boolean;

    // 添加支持雷达图和其他图表类型切换的特殊属性
    _originalType?: string;  // 原始图表类型
    _blockDefaultRendering?: boolean; // 阻止默认数据渲染的标记
    textStyle?: TextStyle;   // 文本样式
    label?: LabelConfig;     // 标签配置
    xAxis?: any;             // X轴配置（简化版）
    yAxis?: any;             // Y轴配置（简化版）
    shading?: string;        // 3D图表着色方式
}
